#include<cstdio>
int n,T,v,z,k,r1=1,r2=1,f1[500005],f2[500005],a[500005],b[500005],c[500005];
int max(int t1,int t2){return t1>t2?t1:t2;}
int xc(int x,int y,int p,int q){
	if(x>p)return 1;
	if(x<p)return 2;
	if(y>q)return 1;
	if(y<q)return 2;
	return 0;
}
void px(int x,int y){
	int r=x,l=y,mia=a[(r+l)/2],mib=b[(r+l)/2];
	while(r<=l){
		while(a[r]<mia)r++;
		while(xc(a[r],b[r],mia,mib)==2)r++;
		while(xc(a[l],b[l],mia,mib)==1)l--;
		if(r<=l){
			v=a[r];a[r]=a[l];a[l]=v;
			v=b[r];b[r]=b[l];b[l]=v;
			r++;l--;
		}
	}
	if(r<y)px(r,y);
	if(x<l)px(x,l);
	return;
}
int main(){
	freopen("fruit.in","r",stdin);
	freopen("fruit.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++){scanf("%d",&c[i]);b[i]=i;}
	z=c[1];
	for(int i=1;i<=n;i++){if(c[i]!=z)break;a[i]=i;k=i;}
	if(z==1)z=0,f2[r2]=k,f1[r1]=0;
	else z=1,f1[r1]=k,f2[r2]=0;
	for(int i=k+1;i<=n;i++){
		if(c[i]==z){
			if(z==1){
				while(f2[r2]>=f1[r1]&&r1>0&&r2>1)f2[r2-1]=max(f2[r2],f2[r2-1]),r1--,r2--;
				f2[r2]++;a[i]=f2[r2];
			}
			if(z==0){
				while(f1[r1]>=f2[r2]&&r1>1&&r2>0)f1[r1-1]=max(f1[r1],f1[r1-1]),r1--,r2--;
				f1[r1]++;a[i]=f1[r1];
			}
		}
		else{
			z=c[i];
			if(z==1){
				r2++;f2[r2]=1;a[i]=1;
			}
			if(z==0){
				r1++;f1[r1]=1;a[i]=1;
			}
		}
	}
//	for(int i=1;i<=n;i++)printf("%d ",a[i]);printf("\n");
	px(1,n);z=1;
	for(int i=1;i<=n;i++){
		if(a[i]!=z){z=a[i];printf("\n");}
		printf("%d ",b[i]);
	}
}
